package com.itheima03;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ReceiveDemo {
    public static void main(String[] args) throws IOException {
        // 创建接收端 socket
        DatagramSocket ds = new DatagramSocket(12345);

        while (true) {
            // 创建数据包
            byte[] bytes = new byte[1024];
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length);

            // 接收
            ds.receive(dp);

            // 解析数据
            System.out.println("接收到的数据：" + new String(dp.getData(), 0, dp.getLength()));
        }

        // 关闭
//        ds.close();
    }
}
